package com.fsm.demo.controller.activiteMq;

import com.fsm.common.activemq.config.DelayedActive;
import lombok.extern.slf4j.Slf4j;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * activiteMq消息推送
 */
@Slf4j
@RestController
@RequestMapping("/activiteMq")
public class HelloController {

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    /**
     * Queue 一对一 及时发送
     * @return
     * @throws Exception
     */
    @GetMapping("/queueTimely")
    public String send1() throws Exception{
        ActiveMQQueue queue = new ActiveMQQueue("aabb");
        new DelayedActive().mqSend(queue,"测试环境数据发送");
        return "send successfully!";
    }

    /**
     * Queue 一对一 延迟发送
     * @return
     * @throws Exception
     */
    @GetMapping("/queueDelayed")
    public void sendOut() throws Exception{
        long delay = 3 * 1000;//设置3s的延迟
        System.out.println("发送消息时间:" + System.currentTimeMillis());
        ActiveMQQueue queue = new ActiveMQQueue("aabb");
        new DelayedActive().delaySend(queue,"测试环境数据发送",delay);
    }

    /**
     * Topic 一对多 延迟发送
     * @return
     * @throws Exception
     */
    @GetMapping("/topicdelayed")
    public void sendTopic() throws Exception{
        long delay = 3 * 1000;//设置3s的延迟
        System.out.println("发送消息时间:" + System.currentTimeMillis());
        ActiveMQTopic topic = new ActiveMQTopic("aabb");
        new DelayedActive().delaySend(topic,"广播测试环境数据发送",delay);
    }

}
